#! /bin/bash
# USER_UID=$(id -u "$CURRENT_USER")
# USER_GID=$(id -g "$CURRENT_USER")

# echo $USER_UID
# docker run -d --name rclone-nutstore-test \
#     -u 1000:1000 \
#     -v /home/test/rclone:/work_dir:shared \
#     -w /work_dir \
#     --entrypoint /bin/bash
#     rclone/rclone:20250929 \
#     -c "while true; do echo hello world; sleep 10; done"
#     # about nutstore:docs --config /work_dir/config.conf

# 创建空容器
docker run -d --name rclone-nutstore-test \
    -w /work_dir \
    -v /home/test/rclone:/work_dir:shared \
    --entrypoint /bin/sh rclone/rclone:20250929 \
    -c "while true; do echo hello world; sleep 10; done"

# docker run -d --name rclone-nutstore-test \
#     -u 1000:1000 \
#     -w /work_dir \
#     -v /home/test/rclone:/work_dir:shared \
#     --entrypoint /bin/sh rclone/rclone:20250929 \
#     -c "while true; do echo hello world; sleep 10; done"

# 进入容器
docker exec -it rclone-nutstore-test /bin/sh


# 首次采用手动同步
# 由于时间太慢，放弃
rclone sync nutstore:docs /work_dir/docs --config /work_dir/config.conf --transfers 2 --checkers 2 --tpslimit 0.3 --tpslimit-burst 5 --max-size 500M --fast-list --retries 5 --retries-sleep 30s --log-file /work_dir/sync.log --log-level INFO --progress --fast-list

# 采用mount的方式，但是容器内提示错误
# 2025/09/30 01:58:29 INFO  : Starting transaction limiter: max 0.3 transactions/s with burst 5
# 2025/09/30 01:58:37 ERROR : Daemon timed out. Failed to terminate daemon pid 75: os: process already finished
# 2025/09/30 01:58:37 CRITICAL: Fatal error: daemon exited with error code 1
# te
# 2025/09/30 01:58:37 INFO  : webdav root 'docs': vfs cache: cleaned: objects 0 (was 0) in use 0, to upload 0, uploading 0, total size 0 (was 0)
# 2025/09/30 01:58:37 NOTICE: mount helper error: fusermount3: fuse device not found, try 'modprobe fuse' first
# 2025/09/30 01:58:37 CRITICAL: Fatal error: failed to mount FUSE fs: fusermount: exit status 1
rclone mount nutstore:docs /work_dir/docs \
  --config /work_dir/config.conf \
  --vfs-cache-mode full \
  --cache-dir /work_dir/.cache \
  --vfs-read-chunk-size 48M \
  --vfs-read-chunk-size-limit 500M \
  --dir-cache-time 168h \
  --tpslimit 0.3 \
  --tpslimit-burst 5 \
  --buffer-size 64M \
  --vfs-fast-fingerprint \
  --daemon \
  --log-file /work_dir/mount.log \
  --log-level INFO

docker ps -a
